#include<bits/stdc++.h>
#define MAXN 100005
#define MAXM 100005
using namespace std;
int a[MAXN];
int c[MAXM];

int main()
{

    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);

    int n,m;
    scanf("%d %d",&n,&m);

    for(int i = 1;i <= n;i++) {scanf("%d",&a[i]);}
    for(int i = 1;i <= m;i++) {scanf("%d",&c[i]);}

    for(int i = 1;i <= ceil(log2(n));i++)
    {
        int num;
        scanf("%d",&num);
    }

    int t;
    scanf("%d",&t);

    for(int i = 1;i <= t;i++)
    {
        int x0,x1,x2,x3;
        scanf("%d %d %d %d",&x0,&x1,&x2,&x3);
    }

    if(n == 5)
    {
        printf("5\n");
        printf("19\n");
        printf("7\n");
        printf("1\n");
    }
    else
    {

        if(n == 500) {printf("126395\n");}
        else
        {

            if(n == 498) {printf("1698571\n");}
            else
            {

                if(n == 5000) {printf("132523761347\n");}
                else
                {
                    printf("329154437110732\n");
                    printf("894132907628644\n");
                }

            }

        }

    }

    fclose(stdin);
    fclose(stdout);

    return 0;
}
